package com.yanqu.road.server.gameplayer.module.activity.dragonboatrace;

import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.activity.dragonboatrace.*;
import com.yanqu.road.entity.activity.dragonboatrace.config.DragonBoatRacePlaceConfig;
import com.yanqu.road.entity.activity.dragonboatrace.config.DragonBoatRaceSpeedConfig;
import com.yanqu.road.entity.enums.eRedHotNotifyType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.logic.bussiness.activity.DragonBoatRaceBusiness;
import com.yanqu.road.pb.dragonboatrace.DragonBoatRaceProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.CrossUnionServerGroupMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.dragonboatrace.DragonBoatRaceMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.config.UnionConfigMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.pb.WorldMessagePb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @Description
 * @Author cwq
 * @Data 2021/5/10 19:46
 */
public class DragonBoatRaceModule extends GeneralModule {

    public DragonBoatRaceUser dragonBoatRaceUser;

    /**
     * 缓存是有联盟奖励否红点
     */
    public boolean hasUnionRedPoint = false;

    public DragonBoatRaceModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        int activityId = DragonBoatRaceMgr.getShowTimeActivityId();
        if (activityId != 0 && SystemOpenMgr.systemOpen(player, eSystemId.DragonBoatRaceActivity.getValue())) {
            DragonBoatRaceUserData userData = DragonBoatRaceBusiness.getDragonBoatRaceUserData(player.getUserId(), activityId);
            if (userData != null) {
                dragonBoatRaceUser = new DragonBoatRaceUser(userData);
                refresh();
            } else {
                initUserData();
            }
        }
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        if (dragonBoatRaceUser != null) {
            if (dragonBoatRaceUser.baseData.isInsertOption()) {
                DragonBoatRaceBusiness.addDragonBoatRaceUserData(dragonBoatRaceUser.baseData);
            } else if (dragonBoatRaceUser.baseData.isUpdateOption()) {
                DragonBoatRaceBusiness.updateDragonBoatRaceUserData(dragonBoatRaceUser.baseData);
            }
        }
        return true;
    }

    @Override
    public void afterLogin() {
        hasUnionRedPoint = false;
        syncConfig();
        initUserData();
        syncUserData();
        synRedPointToCross();
    }

    public void initSystem() {
        syncConfig();
        initUserData();
        syncUserData();
        synRedPointToCross();
    }

    public void initUserData() {
        int activityId = DragonBoatRaceMgr.getShowTimeActivityId();
        if (activityId != 0 && SystemOpenMgr.systemOpen(player, eSystemId.DragonBoatRaceActivity.getValue())
                && (dragonBoatRaceUser == null || dragonBoatRaceUser.baseData.getActivityId() != activityId)) {
            DragonBoatRaceUserData dragonBoatRaceUserData = new DragonBoatRaceUserData();
            dragonBoatRaceUserData.setOp(DataStatus.Insert);
            dragonBoatRaceUserData.setActivityId(activityId);
            dragonBoatRaceUserData.setUserId(player.getUserId());
            dragonBoatRaceUser = new DragonBoatRaceUser(dragonBoatRaceUserData);
        }
    }

    /**
     * 刷新次数 和门客出战
     */
    public void refresh() {
        if (dragonBoatRaceUser != null && dragonBoatRaceUser.baseData.getTimes() > 0 && DateHelper.getDiffDayNum(dragonBoatRaceUser.baseData.getLastTimeJoinTime()) > 0) {
            dragonBoatRaceUser.baseData.setTimes(0);
            dragonBoatRaceUser.baseData.getPatronsList().clear();
            dragonBoatRaceUser.baseData.setUpdateOption();
        }
    }

    /**
     * 刷新比赛信息
     */
    public void refreshGame(long curTime) {
        // 排序
        dragonBoatRaceUser.nodeInfoList.sort((t1, t2) -> Long.compare(t1.time, t2.time));
        while (dragonBoatRaceUser.nodeInfoList.size() > 0) {
            DragonBoatRaceNodeInfo item = dragonBoatRaceUser.nodeInfoList.get(0);
            if (item.time <= curTime) {
                dragonBoatRaceUser.nodeInfoList.remove(0);
                go(item.time);
                if (item.type == 1) {
                    // 产生障碍物
                    dragonBoatRaceUser.produceObstacleDistance = DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_PRODUCE_OBSTACLE_DISTANCE();
                } else {
                    if (item.useProp) {
                        dragonBoatRaceUser.usePropSpeed += item.speed;
                    }
                    dragonBoatRaceUser.curSpeed += item.speed;
                }
            } else {
                break;
            }
        }
        // 计算当前节点情况
        if (curTime > dragonBoatRaceUser.curCalTime) {
            go(curTime);
        }
    }

    /**
     * 创建节点
     *
     * @param type    （0表示速度节点 1表示产生障碍物的节点）
     * @param speed   加速值
     * @param curTime 加速节点
     * @param time    加速时间
     * @param useProp type=0才有用 表示是否是使用道具
     * @return
     */
    public DragonBoatRaceNodeInfo createNodeStatus(int type, long speed, long curTime, int time, boolean useProp) {
        if (type == 0) {
            // 加速
            DragonBoatRaceNodeInfo startNode = new DragonBoatRaceNodeInfo();
            startNode.time = curTime;
            startNode.speed = speed;
            startNode.useProp = useProp;
            dragonBoatRaceUser.nodeInfoList.add(startNode);
            // 还原
            DragonBoatRaceNodeInfo endNode = new DragonBoatRaceNodeInfo();
            endNode.time = curTime + (time * DateHelper.SECOND_MILLIONS);
            endNode.speed = -speed;
            endNode.useProp = useProp;
            if (dragonBoatRaceUser.endTime > endNode.time) {
                dragonBoatRaceUser.nodeInfoList.add(endNode);
            }
            return startNode;
        } else {
            // 遇到障碍物的节点
            DragonBoatRaceNodeInfo meetObstacleNode = new DragonBoatRaceNodeInfo();
            meetObstacleNode.time = curTime;
            meetObstacleNode.type = 1;
            dragonBoatRaceUser.nodeInfoList.add(meetObstacleNode);
            return meetObstacleNode;
        }

    }

    private void go(long endTime) {
        DragonBoatRaceNodeInfo nodeInfo = judgeHitObstacle(endTime);
        if (nodeInfo != null) {
            // 产生新的节点
            refreshGame(endTime);
        } else {
            long passTime = endTime - dragonBoatRaceUser.curCalTime;
            dragonBoatRaceUser.curCalTime = endTime;
            // 到节点所走的路程 （向上取整）
            long s = (dragonBoatRaceUser.curSpeed * 100 * passTime + 1000 - 1) / 1000;
            dragonBoatRaceUser.distance = dragonBoatRaceUser.distance + s;
        }
    }

    /**
     * 判断是否撞击障碍物
     *
     * @param nodeTime
     * @return 返回撞击障碍物的时间
     */
    private DragonBoatRaceNodeInfo judgeHitObstacle(long nodeTime) {
        // 判断是否在产生障碍物区间
        DragonBoatRaceNodeInfo nodeInfo = null;
        if (dragonBoatRaceUser.produceObstacleDistance > 0) {
            // 当前速度对应的屏幕速度
            long s = dragonBoatRaceUser.produceObstacleDistance;
            long diffTime = nodeTime - dragonBoatRaceUser.curCalTime;
            int pixel = calPixel();
            dragonBoatRaceUser.produceObstacleDistance -= ((pixel * diffTime + 1000 - 1) / 1000);
            if (dragonBoatRaceUser.produceObstacleDistance <= 0) {
                // 遇到障碍物的时间
                long meetTime = ((s * DateHelper.SECOND_MILLIONS + pixel - 1) / pixel) + dragonBoatRaceUser.curCalTime;
                long clickDrumLastEndTime = dragonBoatRaceUser.clickDrumLastTime + DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_CLICK_DRUM_KEEP_TIME();
                if (dragonBoatRaceUser.clickDrumLastTime < meetTime && meetTime <= clickDrumLastEndTime) {
                    // 鼓舞时间内 冲破障碍物
                    // 冲破障碍物 加速
                    dragonBoatRaceUser.breakObstacleNum++;
                    long speed1 = (dragonBoatRaceUser.initSpeed * DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_BREAK_OBSTACLE_VALUE() + 1000 - 1) / 1000;
                    nodeInfo = createNodeStatus(0, speed1, meetTime, DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_BREAK_OBSTACLE_TIME(), false);
                } else {
                    // 未冲破障碍物 减速
                    dragonBoatRaceUser.unBreakObstacleNum++;
                    long speed2 = (dragonBoatRaceUser.initSpeed * DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_OBSTACLE_VALUE()) / 1000;
                    nodeInfo = createNodeStatus(0, -speed2, meetTime, DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_OBSTACLE_TIME(), false);
                }
                dragonBoatRaceUser.produceObstacleDistance = 0;
            }
        }
        return nodeInfo;
    }

    /**
     * 根据当前速度算屏幕播放速度
     *
     * @return
     */
    private int calPixel() {
        int pixel = 0;
        for (DragonBoatRaceSpeedConfig item : DragonBoatRaceMgr.getConfig().getSpeedList()) {
            if (dragonBoatRaceUser.usePropSpeed >= item.getExtraSpeed()) {
                pixel = item.getPixel();
            } else {
                break;
            }
        }
        return pixel;
    }


    /**
     * 重置比赛
     */
    public void clearGame() {
        if (dragonBoatRaceUser != null) {
            dragonBoatRaceUser.startTime = 0;
            dragonBoatRaceUser.endTime = 0;
            dragonBoatRaceUser.initSpeed = 0;
            dragonBoatRaceUser.curSpeed = 0;
            dragonBoatRaceUser.curCalTime = 0;
            dragonBoatRaceUser.clickDrumLastTime = 0;
            dragonBoatRaceUser.breakObstacleNum = 0;
            dragonBoatRaceUser.unBreakObstacleNum = 0;
            dragonBoatRaceUser.clickDrumNum = 0;
            dragonBoatRaceUser.distance = 0;
            dragonBoatRaceUser.usePropSpeed = 0;
            dragonBoatRaceUser.produceObstacleDistance = 0;
            dragonBoatRaceUser.produceObstacleTimeList.clear();
            dragonBoatRaceUser.nodeInfoList.clear();
            dragonBoatRaceUser.patronsList.clear();
            dragonBoatRaceUser.usePropMap.clear();
            dragonBoatRaceUser.usePropCdMap.clear();
            dragonBoatRaceUser.useFreePropMap.clear();
        }
    }


    public void syncConfig() {
        int activityId = DragonBoatRaceMgr.getShowTimeActivityId();
        if (activityId != 0 && SystemOpenMgr.systemOpen(player, eSystemId.DragonBoatRaceActivity.getValue())) {
            DragonBoatRaceProto.DragonBoatRaceActivity.Builder config = DragonBoatRaceProto.DragonBoatRaceActivity.newBuilder();
            config.setActivityId(activityId);
            config.setScoreItemId(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_SCORE_ITEM_ID());
            config.setTimes(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_TIMES());
            config.setDailyOpenTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_DAILY_OPEN_TIME());
            config.setDailyEndTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_DAILY_END_TIME());
            config.setEndingTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_ENDING_TIME());
            config.setPatronsNum(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_PATRONS_NUM());
            config.setInitSpeed(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_INIT_SPEED());
            config.setPatronsLevelCoefficient(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_PATRONS_LEVEL_COEFFICIENT());
            config.setGameTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_GAME_TIME());
            config.setGameCdTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_GAME_CD_TIME());
            config.setRandomStartRange(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_RANDOM_START_RANGE());
            config.setRandomEndRange(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_RANDOM_END_RANGE());
            config.setClickDrumCd(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_CLICK_DRUM_CD());
            config.setClickDrumKeepTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_CLICK_DRUM_KEEP_TIME());
            config.setBreakObstacleValue(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_BREAK_OBSTACLE_VALUE());
            config.setBreakObstacleTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_BREAK_OBSTACLE_TIME());
            config.setObstacleValue(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_OBSTACLE_VALUE());
            config.setObstacleTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_OBSTACLE_TIME());
            config.setProduceObstacleDistance(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_PRODUCE_OBSTACLE_DISTANCE());
            config.setPreparationTime(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_PREPARATION_TIME());
            config.setObstaclePixelValue(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_OBSTACLE_PIXEL_VALUE());
            config.setObstacleCueDistance(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_OBSTACLE_CUE_DISTANCE());
            for (Integer propId : DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_ENERGY_ITEM_LIST()) {
                config.addPropList(propId);
            }
            for (Integer propId : DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_FREE_ENERGY_ITEM_LIST()) {
                config.addFreePropList(propId);
            }
            for (DragonBoatRacePlaceConfig placeConfig : DragonBoatRaceMgr.getConfig().getPlaceConfigList()) {
                config.addPlaceConfig(DragonBoatRaceProto.DragonBoatRacePlaceConfigEntity.newBuilder()
                        .setId(placeConfig.getId())
                        .setName(ServerLanguageMgr.getContent(placeConfig.getName(), player.getLanguage()))
                        .setDesc(ServerLanguageMgr.getContent(placeConfig.getDesc(), player.getLanguage()))
                        .setIcon(placeConfig.getIcon())
                        .setPlaceCoordinate(placeConfig.getPlaceCoordinate())
                        .setDistance(placeConfig.getDistance())
                        .setRewards(placeConfig.getRewards())
                        .build());
            }
            for (DragonBoatRaceSpeedConfig speedConfig : DragonBoatRaceMgr.getConfig().getSpeedList()) {
                config.addSpeedConfig(DragonBoatRaceProto.DragonBoatRaceSpeedConfigEntity.newBuilder()
                        .setId(speedConfig.getId())
                        .setName(speedConfig.getName())
                        .setEffect(speedConfig.getEffect())
                        .setExtraSpeed(speedConfig.getExtraSpeed())
                        .setPixel(speedConfig.getPixel())
                        .build());
            }
            player.sendPacket(Protocol.U_DRAGONBOATRACE_CONFIG, config);
        }
    }

    /**
     * 向跨服获取联盟航行信息 和领取信息
     */
    public void synRedPointToCross() {
        int activityId = DragonBoatRaceMgr.getShowTimeActivityId();
        if (activityId == 0 || !SystemOpenMgr.systemOpen(player, eSystemId.DragonBoatRaceActivity.getValue())) {
            return;
        }
        if (StringUtils.isNullOrEmpty(player.getUserInfo().getUnionUid()) && !hasUnionRedPoint) {
            return;
        }
        DragonBoatRaceProto.DragonBoatRaceTotalDistanceAndReceiveInfoGameToCrossMsg.Builder builder = DragonBoatRaceProto.DragonBoatRaceTotalDistanceAndReceiveInfoGameToCrossMsg.newBuilder();
        builder.setActivityId(activityId);
        builder.setUnionId(player.getUserInfo().getUnionUid());
        player.sendPacket(Protocol.C2_DRAGONBOATRACE_GET_DISTANCE_AND_RECEIVE_INFO, builder);
    }

    /**
     * 发送可以领取联盟奖励的红点
     * @param hasUnionReward
     */
    public void synRedPoint(boolean hasUnionReward){
        if (hasUnionRedPoint != hasUnionReward) {
            WorldMessageProto.RedHotNotifyMsg.Builder redHotMsg = WorldMessagePb.parseRedHotNotifyMsg(eRedHotNotifyType.DragonBoatRace.getValue(), hasUnionReward ? 1 : 0, null);
            player.sendPacket(Protocol.U_RED_HOT_NOTIFY, redHotMsg);
            hasUnionRedPoint = hasUnionReward;
        }
    }

    /**
     * 同步红点
     */
    public void synRedPoint(DragonBoatRaceProto.DragonBoatRaceSynUnionInfoCrossToGameMsg synUnionInfoMsg) {
        if (synUnionInfoMsg != null) {
            boolean hasUnionReward = hasUnionReward(synUnionInfoMsg.getTotalDistance(), synUnionInfoMsg.getUnionId(), synUnionInfoMsg.getReceiveInfoListList());
            synRedPoint(hasUnionReward);
        }
    }

    public void syncUserData() {
        if (dragonBoatRaceUser != null) {
            refresh();
            DragonBoatRaceProto.DragonBoatRaceGetUserDataRespMsg.Builder builder = DragonBoatRaceProto.DragonBoatRaceGetUserDataRespMsg.newBuilder();
            builder.setActivityId(dragonBoatRaceUser.baseData.getActivityId());
            builder.addAllPatronsId(dragonBoatRaceUser.baseData.getPatronsList());
            builder.setTimes(dragonBoatRaceUser.baseData.getTimes());
            builder.setLastTimeJoinTime(dragonBoatRaceUser.baseData.getLastTimeJoinTime());
            player.sendPacket(Protocol.U_DRAGONBOATRACE_GET_USER_DATA, builder);
        }
    }

    /**
     * 判断是否能开始比赛
     *
     * @return
     */
    public int canStartGame() {
        int ret = DragonBoatRaceMgr.getActivityEndStatus(player);
        if (ret != 0) {
            return ret;
        }
        if (DragonBoatRaceMgr.isRestTime()) {
            return GameErrorCode.E_DRAGONBOATRACE_ACTIVITY_NO_IN_TIME;
        }
        long curTime = System.currentTimeMillis();
        // 判断是否是活动结束当天
        long todayZeroTime = DateHelper.getZeroTimeStamp(curTime);
        long activityEndZeroTime = DateHelper.getZeroTimeStamp(DragonBoatRaceMgr.getActivityInfo().getEndTime() * 1000);
        if (todayZeroTime == activityEndZeroTime && curTime > (todayZeroTime + DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_DAILY_END_TIME() * DateHelper.HOUR_MILLIONS - DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_ENDING_TIME() * DateHelper.SECOND_MILLIONS)) {
            // 结束前几分钟不能参加比赛
            return GameErrorCode.E_DRAGONBOATRACE_ACTIVITY_NO_IN_TIME;
        }
        if (dragonBoatRaceUser != null) {
            if (dragonBoatRaceUser.baseData.getTimes() >= DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_TIMES()) {
                return GameErrorCode.E_DRAGONBOATRACE_ACTIVITY_PLAY_TIMES_MAX;
            }
            if ((curTime / 1000) - dragonBoatRaceUser.baseData.getLastTimeJoinTime() < DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_GAME_CD_TIME()) {
                return GameErrorCode.E_DRAGONBOATRACE_ACTIVITY_CD;
            }
        }
        return 0;
    }


    /**
     * 是否有可领取的地图奖励
     *
     * @param unionDistance
     * @param receivedInfoList
     * @return
     */
    public boolean hasUnionReward(long unionDistance, String unionId, List<DragonBoatRaceProto.DragonBoatRaceTimesReceiveInfo> receivedInfoList) {
        int activityId = DragonBoatRaceMgr.getShowTimeActivityId();
        if (activityId == 0 || !SystemOpenMgr.systemOpen(player, eSystemId.DragonBoatRaceActivity.getValue()) || StringUtils.isNullOrEmpty(player.getUserInfo().getUnionUid())) {
            return false;
        }
        if (!player.getUserInfo().getUnionUid().equals(unionId)) {
            return false;
        }
        CrossUnionInfo crossUnionInfo = CrossUnionMgr.getUnionInfo(unionId);
        if (crossUnionInfo == null) {
            return false;
        }
        Map<Integer, DragonBoatRaceProto.DragonBoatRaceTimesReceiveInfo> receivedInfoMap = new HashMap<>();
        for (DragonBoatRaceProto.DragonBoatRaceTimesReceiveInfo item : receivedInfoList) {
            receivedInfoMap.put(item.getPlace(), item);
        }
        // 到达的档次
        int receivedPlaceId = dragonBoatRaceUser == null ? 0 : dragonBoatRaceUser.baseData.getPlaceId();
        int crossServerCount = CrossUnionServerGroupMgr.getGroupServerCountByServerId(crossUnionInfo.getServerId());
        int maxMemberCount = UnionConfigMgr.getMaxMemberCount(crossUnionInfo.getExperience(), crossUnionInfo.isCross(), crossServerCount);
        for (DragonBoatRacePlaceConfig item : DragonBoatRaceMgr.getConfig().getPlaceConfigList()) {
            if (receivedPlaceId >= item.getId()) {
                continue;
            }
            if (item.getDistance() > unionDistance) {
                return false;
            }
            DragonBoatRaceProto.DragonBoatRaceTimesReceiveInfo receiveInfo = receivedInfoMap.get(item.getId());
            if (receiveInfo != null && receiveInfo.getReceiveListList().size() > 0) {
                if (receiveInfo.getReceiveListList().size() >= maxMemberCount) {
                    // 领取上限
                    continue;
                }
                if (receiveInfo.getReceiveListList().contains(player.getUserId())) {
                    // 已领过
                    continue;
                }
            }
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        // 测试行驶逻辑
        DragonBoatRaceModule dragonBoatRaceModule = new DragonBoatRaceModule(null);
        DragonBoatRaceUserData dragonBoatRaceUserData = new DragonBoatRaceUserData();
        dragonBoatRaceUserData.setActivityId(1);
        dragonBoatRaceUserData.setUserId(1);
        dragonBoatRaceModule.dragonBoatRaceUser = new DragonBoatRaceUser(dragonBoatRaceUserData);
        long curTime = System.currentTimeMillis();
        dragonBoatRaceModule.dragonBoatRaceUser.startTime = curTime;
        dragonBoatRaceModule.dragonBoatRaceUser.endTime = curTime + DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_GAME_TIME() * DateHelper.MINUTE_MILLIONS;
//        dragonBoatRaceModule.dragonBoatRaceUser.initSpeed = DragonBoatRaceMgr.DRAGONBOATRACE_INIT_SPEED + (200 + DragonBoatRaceMgr.DRAGONBOATRACE_PATRONS_LEVEL_COEFFICIENT - 1) / DragonBoatRaceMgr.DRAGONBOATRACE_PATRONS_LEVEL_COEFFICIENT;
        dragonBoatRaceModule.dragonBoatRaceUser.curSpeed = dragonBoatRaceModule.dragonBoatRaceUser.initSpeed;
        dragonBoatRaceModule.dragonBoatRaceUser.curCalTime = curTime;
        Random random = new Random(curTime);
        long tempTime = curTime;
        while (true) {
            int meetTime = random.nextInt(DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_RANDOM_END_RANGE() - DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_RANDOM_START_RANGE()) + DragonBoatRaceMgr.getConfig().getDRAGONBOATRACE_RANDOM_START_RANGE();
            System.out.println(meetTime);
            tempTime += meetTime * DateHelper.SECOND_MILLIONS;
            if (tempTime < dragonBoatRaceModule.dragonBoatRaceUser.endTime) {
                dragonBoatRaceModule.dragonBoatRaceUser.produceObstacleTimeList.add(tempTime);
                dragonBoatRaceModule.createNodeStatus(1, 0, tempTime, 0, false);
            } else {
                break;
            }
        }
        dragonBoatRaceModule.refreshGame(curTime + 10000);

        dragonBoatRaceModule.refreshGame(curTime + 20000);
    }

}
